package main.Q1601_1700;

public class Q1661_1670 {
    public static void main(String[] args) {
        System.out.println("Question1661：");
        System.out.println("Question1662：");
        System.out.println("Question1663：");
        System.out.println("Question1664：");
        System.out.println("Question1665：");
        System.out.println("Question1666：");
        System.out.println("Question1667：");
        System.out.println("Question1668：");
        System.out.println("Question1669：合并两个链表");
        System.out.println("Question1670：");
    }
}

class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
        this.val = val;
    }

    ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }
}

class Question1669 {
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode slow = list1, fast = list1, list2End = list2;
        for (int i = 0; i <= b - a; i++) {
            fast = fast.next;
        }
        while (list2End.next != null) {
            list2End = list2End.next;
        }
        for (int i = 1; i < a; i++) {
            slow = slow.next;
            fast = fast.next;
        }
        slow.next = list2;
        list2End.next = fast.next;
        return list1;
    }
}